/*
 * fish.h
 *
 *  Created on: Mar 13, 2011
 *      Author: Sharks group.
 */

#define LIMIT_SPEECH_PERSON 4
#define LIMIT_BLOOD_MAX_PERSON 10
#define LIMIT_BLOOD_MIN_PERSON 0

typedef struct tagPerson
{
	unsigned short x;
	unsigned short y;
	unsigned short initx;
	unsigned short inity;
	unsigned short speech;
	unsigned short blood;
//	unsigned short size;

	unsigned short limitx1;
	unsigned short limitx2;
	unsigned short limity1;
	unsigned short limity2;

}Person;

Person person; //singleton: there is only 1 person, cannot new another one
void setUpPerson(){
	person.x = 5;
	person.y =10;
	person.speech=1;
	person.blood =5;

	person.limitx1=LIMIT_SPEECH_PERSON;
	person.limitx2=225;
	person.limity1=LIMIT_SPEECH_PERSON;
	person.limity2=135;
}

//Use arrow key to handle Person.
void handlePersonByKeyboard(){
	if (!((*KEYS) & KEY_UP)) {
		person.y -= person.speech;
	}
	if (!((*KEYS) & KEY_DOWN)) {
		person.y += person.speech;
	}
	if (!((*KEYS) & KEY_RIGHT)) {
		person.x += person.speech;
	}
	if (!((*KEYS) & KEY_LEFT)) {
		person.x -= person.speech;
	}
	recheckPersonPosition();
}

void recheckPersonPosition() {
	if (person.y < person.limity1) {
		person.y = person.limity1;
	}
	if (person.y > person.limity2) {
		person.y = person.limity2;
	}
	if (person.x < person.limitx1) {
		person.x = person.limitx1;
	}
	if (person.x > person.limitx2) {
		person.x = person.limitx2;
	}
}

//increase, decrease blood and speech
changePowerPerson(Person * person, unsigned short value){
	person->blood  += value;
	person->speech += value;
	if(person->speech >LIMIT_SPEECH_PERSON){
		person->speech = LIMIT_SPEECH_PERSON;
	}
	//minimum speech must be 1
	if(person->speech<1){
		person->speech = 1;
	}
	//maximum blood must be 10
	if(person->blood >LIMIT_BLOOD_MAX_PERSON){
		person->blood = LIMIT_BLOOD_MAX_PERSON;
	}
	//minimum blood is 0
	if(person->blood <= LIMIT_BLOOD_MIN_PERSON){
		person->blood = LIMIT_BLOOD_MIN_PERSON;
	}
}




